/******************************************************************************** This program was developed by David Pitts on July 27, 1995 based upon a * program written by Jiawen Yang (which converts viff format to pic format). * This program reads a TARGA format, allows the student to perform processing * and outputs a targa format which can be displayed on the Sun Solaris system */ # include "stdio.h" /*************************************/ /* Function Prototypes */ /*************************************/ void Open_io(void); void Read_write_hdr(void); void Pause(void); void Read_pixels(void); void Modify_image(void); void Write_pixels(void); /*************************************/ /* Globals */ /*************************************/ FILE *fpin,*fpout; int gpicval[512][512],gnew[512][512],gmaxx,gmaxy; unsigned char gdata_char; int main(void) /* read in a B & W targa file, allows processing, and */ /* writes out a targa file of the same size as input */ /* max size of targa file is 512 lines by 512 pixels */ /* The user should change the "Modify_image" function in */ /* order to perform image processing functions */ { Open_io (); /* open an input and an output file */ Read_write_hdr(); Pause(); Read_pixels(); Modify_image(); Write_pixels(); } /* end of main program */ /* _______________________________________________________________ */ void Open_io(void) /* open an input file and an output file */ { fpin=fopen("lenna.tga","rb"); /* name of input targa file */ if (fpin == NULL) { printf("cannot open input file\n"); exit(0); } fpout=fopen("new.tga","wb"); /* name of output targa file */ if (fpout == NULL) { printf("cannot open output file\n"); exit(1); } } /* _______________________________________________________________ */ void Read_write_hdr(void) { int j,hdr[18]; for (j=0;j<18;j++) { fscanf(fpin,"%c",&gdata_char); /* read input hdr */ fprintf(fpout,"%c",gdata_char); /* write output hdr */ hdr[j]=gdata_char; /* convert to integer */ /* for subsequent access */ /* by image proc. routines */ printf("Location=%d,Value=%d\n",j,hdr[j]); } printf("\ncompleted reading and writing the 18 bytes header\n"); gmaxy=256*hdr[15]+hdr[14]; /* number of lines in image */ printf("\nNumber of lines in the image = %d\n",gmaxy); /* k & y */ gmaxx=256*hdr[13]+hdr[12]; /* number of pixels per line */ printf("\nNumber of pixels per line =%d\n",gmaxx); /* j & x */ if (hdr[16] != 8) { printf("This image file does not have 8 bits per pixel, exeuction halted\n"); exit(2); } if (gmaxx > 512 || gmaxy > 512) { printf("Image size greater than 512, execution halted\n"); exit(3); } } /* _______________________________________________________________ */ void Pause(void) /* wait for carriage return to continue */ { int k,j; printf("\n"); printf("Press return to continue\n"); scanf("%c",&gdata_char); } /* _______________________________________________________________ */ void Read_pixels(void) { int k,j; for (k=0;k